package com.qf.resp;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultEntity<T> {

    private static final String SUCCESS = "success";

    private static final String ERROR = "error";

    private String status;

    private Integer code;

    private String msg;


    private T data;

    // 响应成功
    public static ResultEntity success() {
        return new ResultEntity(SUCCESS, 200, "操作成功", null);
    }

//    public static ResultEntity success(String token) {
//        return new ResultEntity(SUCCESS, 200, token,null);
//    }

    public static ResultEntity success(Object target) {

        if (target instanceof Boolean) {
            if ((boolean) target) {
                return success();
            } else {
                return error("你有的数据库有误");
            }
        } else {
            return new ResultEntity(SUCCESS, 200, "操作成功", target);
        }
    }

    public static ResultEntity error(String msg)
    {
        return new ResultEntity(ERROR, 500, msg, null);
    }
}
